# Contributor: Karim Kanso <kaz.kanso@gmail.com>
# Maintainer: Karim Kanso <kaz.kanso@gmail.com>
pkgname=barnyard2
pkgver=2.1.14_git20160413
_gitrev=f9186f2478bfb096c5a43bdb0c91985c3ef3e20d
pkgrel=1
pkgdesc="Parser for Snort unified/unified2 files"
url="https://github.com/firnsy/barnyard2"
# riscv64, ppc64le, loongarch64: blocked by snort -> luajit
arch="all !ppc64le !riscv64 !loongarch64"
license="GPL-2.0-only"
depends="snort"
install="$pkgname.pre-install"
makedepends="libtool autoconf automake make libpcap-dev libdnet-dev daq-dev
	mariadb-connector-c-dev libpq-dev"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.zip::https://github.com/firnsy/barnyard2/archive/$_gitrev.zip
	10-fix-output-fwsam-and-database_cache.patch
	20-disable-outputs.patch
	30-remove-warnings.patch
	barnyard2.confd
	barnyard2.initd"
builddir="$srcdir/"$pkgname-$_gitrev
pkgusers="barnyard2"
pkggroups="barnyard2"

prepare() {
	default_prepare
	sed -i -e 's|^output alert_fast:|# &|' etc/barnyard2.conf
	sed -i -E 's|^#(config interface:)|\1|' etc/barnyard2.conf
	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--with-mysql \
		--with-postgresql \
		--disable-ipv6 \
		--disable-prelude \
		--disable-mysql-ssl-support \
		--disable-aruba \
		--without-tcl \
		--without-oracle
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -D -m 755 ../barnyard2.initd "$pkgdir"/etc/init.d/barnyard2
	install -D -m 644 ../barnyard2.confd "$pkgdir"/etc/conf.d/barnyard2
	mkdir -m 770 -p "$pkgdir"/var/log/barnyard2
	chown barnyard2:barnyard2 "$pkgdir"/var/log/barnyard2
}

sha512sums="6b9a4b87287f6386f1df65a9138e243a69ab1b59f2a30c2cbb5d52630a64ed71b56293d26e1672b494cfe4b0b48ab50038b356c8f95ef22a19628847634ffd7d  barnyard2-2.1.14_git20160413.zip
2a5c8b44ecc4b6377d2d045271f2ca22ed4643eee3777ca7aaf522c72fb928367633256f00a4673201434b57f3c02ae6f8e8320a40ec3e2720a6925dc2b30162  10-fix-output-fwsam-and-database_cache.patch
b1348f9c8132899faef8e60fc81efd8f6477a268ed69e2d55b623c13e303ca681fde842f23ed15fd5c61836467e571e8fa8f2a39948653d54955927b3e306783  20-disable-outputs.patch
7dccc629d7fb6c3f98c7f3cff6acfb27dea88a2f3c756c37cafb3a42a727c61ec8f853c044a8358bb3223eb5078dc508d63d721cdb37c6deb7b87cfb52bb1773  30-remove-warnings.patch
20b6a0bb7f72f252d8d7547831aae7a79b7dd3dd327fd211c28013e7928f10480bf7d7114adf8baae2cf979fb5b65e5f001f9597a8df53569437e2396de67d05  barnyard2.confd
60a6cf49a268d41253057af99839e68f3b69a156f56318e687e0cbf96e521f7b99051748163c4f02ca952e481b66b01acbb06d1af243d646125e9d0a6b32da3b  barnyard2.initd"
